﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
namespace Shutterstock.Salesforce.SSISDownload.SFTableOperations
{
    public class TableUtilities
    {
        public static Dictionary<string, string> GetDBCasedNames(string tableName, SqlConnection conn)
        {
            string sql = String.Format("select name from sys.columns where object_id=object_id('{0}')", tableName);
            Dictionary<string, string> final = new Dictionary<string, string>();
            using (SqlCommand cmd = conn.CreateCommand())
            {
                cmd.CommandText = sql;
                using (SqlDataReader dr = cmd.ExecuteReader())
                {
                    while (dr.Read())
                    {
                        string name = dr[0].ToString();
                        if (!final.ContainsKey(name.ToUpper()))
                        {
                            final.Add(name.ToUpper(), name);
                        }

                    }
                }

            }
            return final;
        }

        public static List<string> GetDBDecimals(string tableName, SqlConnection conn)
        {
            List<string> final = new List<string>();
            string sql = String.Format("select name from sys.columns where object_id=object_id('{0}') and system_type_id=106", tableName);
            using (SqlCommand cmd = conn.CreateCommand())
            {
                cmd.CommandText = sql;
                using (SqlDataReader dr = cmd.ExecuteReader())
                {
                    while (dr.Read())
                    {
                        string name = dr[0].ToString();
                        final.Add(name);

                    }
                }

            }
            return final;
        }

    }
}
